import sys, random

def chop(value, integers):
    if len(integers) > 0:
        middle = len(integers)/2
        if integers[middle] == value:
            return middle
        elif value > integers[middle]:
            idx = chop(value, integers[middle+1:len(integers)])
            idx = -1 if idx == -1 else middle + idx + 1
        elif value < integers[middle]:
            idx = chop(value, integers[0:middle])
        return idx
    else:
         return -1

assert(-1 == chop(3, []))
assert(-1 == chop(3, [1]))
assert(0 ==  chop(1, [1]))

assert(0 == chop(1, [1, 3, 5]))
assert(1 == chop(3, [1, 3, 5]))
assert(2 == chop(5, [1, 3, 5]))
assert(-1 == chop(0, [1, 3, 5]))
assert(-1 == chop(2, [1, 3, 5]))
assert(-1 == chop(4, [1, 3, 5]))
assert(-1 == chop(6, [1, 3, 5]))

assert(0 == chop(1, [1, 3, 5, 7]))
assert(1 == chop(3, [1, 3, 5, 7]))
assert(2 == chop(5, [1, 3, 5, 7]))
assert(3 == chop(7, [1, 3, 5, 7]))
assert(-1 == chop(0, [1, 3, 5, 7]))
assert(-1 == chop(2, [1, 3, 5, 7]))
assert(-1 == chop(4, [1, 3, 5, 7]))
assert(-1 == chop(6, [1, 3, 5, 7]))
assert(-1 == chop(8, [1, 3, 5, 7]))

assert(4 == chop(4, [0, 1, 1, 3, 4, 5, 5, 5, 8, 8]))

if len(sys.argv) > 1:
    n = int(sys.argv[1])
    m = int(sys.argv[2])
    l = []
    for i in range(1,n):
        l.append(random.randint(1,m))
    l.sort()
    randVal = l[random.randint(1,n)]
    assert(randVal == l[chop(randVal, l)])
